package com.atguigu.gmall.product.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

// 用于被其他微服务调用
@RestController
@RequestMapping("/api/product/inner")
public class ProductApiController {

    private ManagerService managerService;

    @Autowired
    public ProductApiController(ManagerService managerService) {
        this.managerService = managerService;
    }

    @GetMapping("/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId) {
        return this.managerService.getSkuInfo(skuId);
    }

    @GetMapping("/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id") Long category3Id) {
        return this.managerService.getCategoryViewByCategory3Id(category3Id);
    }

    @GetMapping("/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId) {
        return this.managerService.getSkuPrice(skuId);
    }

    @GetMapping("/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable("skuId") Long skuId, @PathVariable("spuId") Long spuId) {
        return this.managerService.getSpuSaleAttrListCheckBySku(skuId, spuId);
    }

    @GetMapping("/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable("spuId") Long spuId) {
        return this.managerService.getSkuValueIdsMap(spuId);
    }

    @GetMapping("/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> findSpuPosterBySpuId(@PathVariable Long spuId) {
        return this.managerService.findSpuPosterBySpuId(spuId);
    }

    @GetMapping("/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable("skuId") Long skuId) {
        return this.managerService.getAttrList(skuId);
    }

    // 首页数据查询三级分类数据
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        // JSONObject 底层其实就是 Map
        List<JSONObject> list = this.managerService.getBaseCategoryList();
        return Result.ok(list);
    }

}
